package com.wuaiy.userCenter.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FileUtil
{
	public String readFile(File sourceFile)
	{
		try
		{
			return this.readFile(new FileInputStream(sourceFile));
		} catch (FileNotFoundException e)
		{
			ConstatFinalUtil.LOGGER.error("文件不存在;路径:{}", sourceFile, e);
		}
		return "";

	}

	public String readFile(InputStream is)
	{
		StringBuffer sb = new StringBuffer();
		BufferedReader br = null;
		try
		{
			br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
			String line = "";
			while ((line = br.readLine()) != null)
			{
				/* 处理注释 */
				line = line.trim();
				if ("".equalsIgnoreCase(line) || line.startsWith("//"))
				{
					continue;
				}

				sb.append(line);
			}
		} catch (Exception e)
		{
			ConstatFinalUtil.LOGGER.error("读取输入流内容失败了:", e);
		} finally
		{
			try
			{
				if (br != null)
				{
					br.close();
				}
			} catch (IOException e)
			{
				ConstatFinalUtil.LOGGER.error("读取输入流内容关闭时失败了:", e);
			}
		}
		return sb.toString();
	}
}
